package main

import "fmt"

const (
	ConstFruitApple  string = "apple"
	ConstFruitBanana string = "banana"
)

type Fruit interface {
	PrintName()
}

type Apple struct {
	Name string
}

func (f Apple) PrintName() {
	fmt.Println(f.Name)
}

// CreateFruit 工厂方法
func CreateFruit(name string) Fruit {
	switch name {
	case ConstFruitApple:
		return new(Apple)
	}
	return nil
}

func main() {
	apple := CreateFruit(ConstFruitApple).(Apple)
	apple.Name = "苹果"
	apple.PrintName()
}
